<?php

/**
* @copyright   (C) 2010 iJoomla, Inc. - All rights reserved.
* @license  GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) 
* @author  iJoomla.com webmaster@ijoomla.com
* @url   http://www.ijoomla.com/licensing/
* the PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript  
* are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 
* More info at http://www.ijoomla.com/licensing/
*/

defined('_JEXEC') or die('Restricted Access');
JHtml::_('behavior.tooltip');

include(JPATH_ROOT.DS."administrator".DS."components".DS."com_surveys".DS."left.php");
jimport('joomla.html.pane');

$document =& JFactory::getDocument();
$document->addStyleSheet("components/com_surveys/css/survey.css");

$app = JFactory::getApplication('administrator');
$limistart = $app->getUserStateFromRequest('com_surveys.surveys'.'.list.start', 'limitstart');
$limit = $app->getUserStateFromRequest('com_surveys.surveys'.'.list.limit', 'limit');

$search = JRequest::getVar("search", "");
$survey_selected = JRequest::getVar("survey_filter", "");

$s_id = JRequest::getVar("s_id", "", "get");
if($s_id != ""){
	$survey_selected = $s_id;
}

?>

<form action="index.php" method="post" name="adminForm" id="adminForm">
	
	<table width="100%">
		<tr>
			<td align="right">
				<a target="_blank" href="http://www.ijoomla.com/redirect/survey/videos/create.htm" class="video">Video Tutorial <img src="components/com_surveys/images/icon_video.gif"></a>
			</td>
		</tr>	
	</table>
	
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminheading">
		<tr>
			<td ><h2 style="color:#669900"><img src="<?php echo JUri::base();?>components/com_surveys/images/icons/pages.png" width="48" height="48" align="middle" /><?php echo JText::_("COM_SURVEYS_PAGES_MANAGER"); ?></h2></td>
			<td align="right" valign="bottom"> 
				<table align="right">
					<tr>
						<td align="right">
						<?php
							echo $this->getSurveysList($survey_selected);
						?>
						</td>						
					</tr>
					<tr>
						<td nowrap valign="bottom">
							<table align="right">
								<td valign="middle" align="right">
									<?php echo JText::_("COM_SURVEYS_FILTER");?>: <input type="text" name="search" value="<?php echo $search; ?>" class="text_area" onChange="document.adminForm.submit();" />
								</td>
								<td valign="middle">
									<input type="submit" name="submit_btn" value="<?php echo JText::_("COM_SURVEYS_GO");?>" />
								</td>
							</table>
						</td>
					</tr>				
				</table>
			</td>			
		</tr>		
	</table>

	<table cellpadding="9" cellspacing="0" border="0" width="100%" class="adminlist">
		<tr>
			<th width="2%" align="center">#</th>
			<th width="2%" align="center"><input type="checkbox" name="toggle" value="" onclick="checkAll(this);" /></th>
			<th width="30%" align="left"><?php echo JText::_("COM_SURVEYS_PAGE_NAME"); ?></th>
			<th width="10%" align="center"><?php echo JText::_("COM_SURVEYS_SHOW_TITLE"); ?></th>
			<th width="10%" align="center"><?php echo JText::_("COM_SURVEYS_SURVEY_PUBLISHED"); ?></th>
			<th width="10%" colspan="2" align="center"><?php echo JText::_("COM_SURVEYS_SURVEY_REORDER"); ?> </th>
			<th width="10%" align="center">
				<table cellpadding="0" cellspacing="0">
					<tr>
						<td style="padding-left:0px;padding-right:0px;border:none"><?php echo JText::_("COM_SURVEYS_SURVEY_ORDER"); ?></td>
						<td style="padding-left:2px;padding-right:0px;border:none"><a class="saveorder" href="javascript: saveorder(<?php echo count($this->items)-1; ?>, 'saveorder')"></a></td>
					</tr>
				</table>			 			
			</th>
			<th width="15%" align="center"> <?php echo JText::_("COM_SURVEYS_SURVEY_NAME"); ?> </th>
			<th width="11%" align="center"> <?php echo JText::_("COM_SURVEYS_PAGE_ID"); ?></th>
			<th width="10%" align="center"> <?php echo JText::_("COM_SURVEYS_QUESTIONS"); ?></th>
		</tr>
	<?php
		$k = $limistart+1;
		$j = 0; 
		for($i=0; $i<count($this->items); $i++){			
			$item = $this->items[$i];			
			//$img = $row->published ? 'tick.png' : 'publish_x.png';
			//$task = $row->published ? 'unpublish' : 'publish';
			//$database->setQuery("SELECT count(q_id) FROM #__ijoomla_surveys_questions WHERE s_id=$row->s_id AND page_id=$row->page_id");											
			//list($questions)=$database->loadRow();										
			//$database->setQuery("SELECT title FROM #__ijoomla_surveys_surveys WHERE s_id=".$row->s_id);											
			//list($survey_name)=$database->loadRow();	  	 
			$show_title = $item->show_title ? 'required.png':'unrequired.png';
			$show_t = "";
			if(isset($item->show_title) && $item->show_title == "1"){
				$show_t = "unshowtitle";
			}
			else{
				$show_t = "showtitle";
			}
						
	?>
		<tr class="<?php echo "row".$j; ?>">
			<td align="center"><?php echo $k; ?></td>
			<td align="center"><?php echo JHtml::_('grid.id', $i, $item->id); ?></td>
			<td align="left" ><a href="index.php?option=com_surveys&controller=newpage&id=<?php echo $item->id; ?>" ><?php echo stripslashes($item->title); ?></a></td>
			<td align="center">
				<a href="javascript: void(0);" onclick="return listItemTask('cb<?php echo $i;?>','<?php echo $show_t?>')"><img src="<?php echo JUri::root(); ?>administrator/components/com_surveys/images/<?php echo $show_title;?>" border="0" alt="" /></a>
			</td>
			<td align="center"><?php echo JHTML::_('grid.published', $item->published, $i); ?></td>
			<td align="center">
				<?php echo $this->pagination->orderUpIcon($i); ?>
			</td>
			<td align="center">
				<?php echo $this->pagination->orderDownIcon($i, count($this->items)); ?>
			</td>
			
			
			<td align="center">
				<input type="text" name="order[<?php echo $item->id; ?>]" size="5" value="<?php echo $item->ordering; ?>" class="text_area" style="text-align:center;"/>
			</td>
			<td align="center"><?php echo stripslashes($item->survey_name); ?></td>
			<td align="center"><?php echo $item->id?></td>
			<td align="center"><a href="index.php?option=com_surveys&controller=questions&p_id=<?php echo $item->id; ?>"><?php echo $this->getQuestions($item->id); ?></a></td>
		</tr> 
		<?php
			$k ++;
			$j = 1 - $j;
		}
		?>
		<tfoot>
			<tr>
				<td colspan="16">
					<?php echo $this->pagination->getListFooter(); ?>
				</td>
			</tr>
		</tfoot>
	</table>
	
	<input type="hidden" name="option" value="com_surveys" />
	<input type="hidden" name="controller" value="pages" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	<?php echo JHtml::_('form.token'); ?>
</form>

</td></tr></table>
<p><center><?php echo JText::_("COM_IJOOMLA_SURVEYS_POWERED_BY") ; ?>&nbsp;<a href='http://www.ijoomla.com' target='_blank'><?php echo JText::_("COM_SURVEYS_SURVEY"); ?></a></center></p>	